/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.easyedu.dictionary.gui.actions;

import eu.easyedu.dictionary.api.model.Dictionary;
import eu.easyedu.dictionary.api.util.AbstractOpenDictionaryAction;
import eu.easyedu.dictionary.gui.MainDictionaryTopComponent;
import eu.easyedu.dictionary.gui.resources.Bundle;
import java.awt.event.ActionEvent;
import java.util.Collection;
import javax.swing.Action;
import org.openide.util.Lookup;
import org.openide.util.Lookup.Item;
import org.openide.util.Utilities;
import org.openide.windows.TopComponent;

/**
 *
 * @author hlavki
 */
public class OpenDictionaryAction extends AbstractOpenDictionaryAction {

    private static final long serialVersionUID = 1L;

    public OpenDictionaryAction() {
        this(Utilities.actionsGlobalContext());
    }

    private OpenDictionaryAction(Lookup context) {
        super(Bundle.getMessage("OpenDictionaryAction.text"));
        this.context = context;
    }

    public void actionPerformed(ActionEvent e) {
        init();
        Collection<? extends Item<Dictionary>> items = lookupResult.allItems();
        for (Item<Dictionary> item : items) {
            TopComponent win = MainDictionaryTopComponent.findInstance(item.getInstance());
            win.open();
            win.requestActive();
        }
    }

    public Action createContextAwareInstance(Lookup actionContext) {
        return new OpenDictionaryAction(actionContext);
    }
}
